package com.ft.adbix.core.ad;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.ft.adbix.core.ad.base.BaseAd;
import com.ft.adbix.core.listener.NativeListener;
import com.ft.adbix.core.response.Ad;
import com.ft.adbix.core.view.NativeAdView;
import com.ft.adbix.utils.UIUtils;

public class NativeAd extends BaseAd {

    private NativeListener listener;
    private NativeAdView adView;

    public NativeAd(Context context, Ad adData) {
        super(context, adData);
    }

    public void setNativeAdListener(NativeListener listener) {
        this.listener = listener;
    }

    public View getAdView() {
        return adView;
    }

    public void renderAd() {
        if (adView == null) {
            //默认上图下文
            adView = new NativeAdView(context);
            adView.renderView(adData, listener);
        }
    }

    public String getTitle() {
        return adData.getTitle();
    }

    public String getDesc() {
        return adData.getDesc();
    }

    public String getIconUrl() {
        return adData.getImageUrl();
    }

    public String getImageUrl() {
        return adData.getImageUrl();
    }

    public String[] getImageList() {
        return adData.getImageUrlList();
    }

    public boolean isVideo() {
        return adData.getVideo() != null && !TextUtils.isEmpty(adData.getVideo().getUrl());
    }

    public String getAdTarget() {
        return "ADBIX";
    }

    @Override
    public void release() {
        if (adView != null) {
            UIUtils.removeFromParent(adView);
            adView = null;
        }
    }
}
